package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.*;
import com.ruoyi.system.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import com.ruoyi.common.config.Global;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.framework.util.ShiroUtils;


/**
 * 首页 业务处理
 *
 * @author ruoyi
 *         caccb850-ec0b-4823-bfb0-fde46839ed51
 */
@Controller
public class SysIndexController extends BaseController {
    @Autowired
    private ISysMenuService menuService;

    @Autowired
    private ISysDeptService deptService;

    @Autowired
    private ISysConfigService configService;


    // 系统首页
    //fe6e48fd-3c01-42fd-b707-6cea3535a818
    @GetMapping("/index")
    public String index(ModelMap mmap) {
        // 取身份信息
        SysUser user = ShiroUtils.getSysUser();
        // 根据用户id取出菜单
        List<SysMenu> menus = menuService.selectMenusByUser(user);

//        System.out.println("登录成功" + user);
//        List<SysRole> roles = user.getRoles();
//        for (int i = 0; i < roles.size(); i++) {
//
//            String roleKey = roles.get(i).getRoleKey();
        //只返回当前用户扮演角色下的医院列表 且为卫健委管理员/超级管理员
//            if (roleKey.indexOf("admin_m") == -1 || roleKey.equals("admin")) {
//                //普通用户设置session
//                getSession().setAttribute("hospital_id", user.getDeptId());
//                getSession().setAttribute("hospital_name", user.getDeptName());

//            }
        //获取session
        //平台管理员
//        }

        //获取当前用户机构下的 机构
        Long deptId = user.getDeptId();
        List<SysDept> sysDepts = deptService.selectHospital(deptId);
//        System.out.println("sysDepts" + sysDepts);
        mmap.put("deptList", sysDepts);
        mmap.put("menus", menus);
        mmap.put("user", user);
        mmap.put("copyrightYear", Global.getCopyrightYear());
        mmap.put("name", Global.getName());
        mmap.put("demoEnabled", Global.isDemoEnabled());
        // 首页是否显示统计图大屏
        String isShowDPStr = configService.selectConfigByKey("sys.main.homePage");
        mmap.put("homePage", (!StringUtils.isEmpty(isShowDPStr) && isShowDPStr.equals("true")) ? true : false);
        return "index";
    }

    // 切换主题
    //0f874ba8-6031-4321-9d47-1888ffe925da
    @GetMapping("/system/switchSkin")
    public String switchSkin(ModelMap mmap) {
        return "skin";
    }

    // 院端院端页面
    //30398c72-c2a4-47c4-be16-a5c1f84ada2d
    @GetMapping("/system/main")
    public String main(ModelMap mmap) {
        mmap.put("version", Global.getVersion());
        return "main";
    }


    // 局端页面
    //1eb77ae7-afe4-46dd-9c2e-17078abc89fc
    @GetMapping("/system/main_v1")
    public String main_v1(ModelMap mmap) {
        mmap.put("version", Global.getVersion());
        return "main_v1";
    }
    @GetMapping("/system/main_v2")
    public String main_v2(ModelMap mmap) {
        mmap.put("version", Global.getVersion());
        return "main_v2";
    }
    @Autowired
    private ISysDistrictsService SysDistrictsService;

    /**
     * @return
     *
     * @author XiaoYi...
     *         可视化大屏
     * @date 2020/5/26 9:20
     *         47c05348-0b0c-426f-aac2-fc60e32474c8
     */
    @GetMapping("/visual/main_v1")
    public String visual_main_v1(ModelMap mmap) {
        //获取用户的位置区县信息
        SysUser user = ShiroUtils.getSysUser();
        SysDept dept = user.getDept();
        //获取地区id
        if (dept.getDistrictsId() > 0) {
            SysDistricts sysDistricts = SysDistrictsService.selectSysDistrictsById(dept.getDistrictsId());
            mmap.put("mapPoint", sysDistricts.getExtName());
        } else
            mmap.put("mapPoint", "中国");
        return "visual/index";
    }

    //02f1061a-8b49-438a-a79c-a90f5388b0f6
    @GetMapping("/visual/map")
    public String map() {
        return "visual/map";
    }


}
